/**
 * @Title: Config.java
 * @Package boco.common.util
 * @Description: TODO  配置参数常量
 * @author li_xiaoyue
 * @version 2013-4-2
 */
package com.hktf.corelib.utils;

import android.app.Dialog;
import android.os.Build;

import com.hktf.corelib.R;
import com.hktf.corelib.jsonbean.UserDto;
import com.hktf.corelib.jsonbean.UserInfo;

import java.io.File;
import java.io.IOException;

/**
 * 配置参数常量
 *
 * @author li_xiaoyue
 * @date 2013-4-2 上午9:42:31
 */
public class Config {


    public static boolean NEED_UPGRADE;//是否有更新
    public static final String SDCARD0 = "/storage/sdcard0";
    public static final String SDCARD1 = "/storage/sdcard1";
    public static final String SDCARD2 = "/mnt/extsd/";
    // 北汽项目 url




    public static final String DEFAULT_VDI_VERSION = "000000000";

    public static String DECRYPTRESULT = "";

    /**
     * 所有日志开关
     */
    public static boolean LOG_OFF = false;

    /**
     * debug日志开关
     */
    public static boolean LOG_OFF_DEBUG = false;
    public static String APP_STYLE = "";
    public static String APP_PATH=CommUtils.getString(R.string.app_path);
    public static String MNTPATH = "/mnt/extsd" + "/" + APP_PATH + "/"
            + "Diagnostics/";
    public static String ROOT_DIR = android.os.Environment
            .getExternalStorageDirectory().getAbsolutePath();
    public static String BASE_CONFIG_PATH = android.os.Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + "/"
            + APP_PATH
            + "/" + "Diagnostics/";
    public static String ATS_PATH = android.os.Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + "/"
            + APP_PATH
            + "/";
    public static String ATS_PATHs = APP_PATH;
    //相册目录
    public static String PrivateSysPhotoPath = android.os.Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + "/"
            + "DCIM/Camera"
            + "/";
    //相册目录
    public static String SysPhotoPath = android.os.Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + "/"
            + "DCIM/Camera"
            + "/";
    //Diagnostics下的子文件夹目录
    public static String PUBLICRES = "PublicRes/";
    public static String MENURES = "MenuRes/";
    public static String DIAGNOSTICSYSRES = "DiagnosticSysRes/";
    public static String DIAGNOSTICUSERDATA = "DiagnosticUserData/";
    public static String FLASHZIPFILES = "FlashZipFiles/";
    public static String vdiVoltage = "0.00V";



    public static int DTC_CODE = 0;
    public static int ECU_CODE = DTC_CODE + 1;
    public static int FREEZFRAMEN_CODE = ECU_CODE + 1;
    public static int DATASTREAM_COED = FREEZFRAMEN_CODE + 1;
    public static int PHOTO_CODE = DATASTREAM_COED + 1;
    public static int SHOOT_CODE = PHOTO_CODE + 1;
    public static int FREEZFRAMEN_DATASTREAM_COED = SHOOT_CODE + 1;

    public static String LOGPATH;
    public static UserDto USERINFO = null;// 保存当前的用户
    public static int VDIISBIND = -1;// 当前的vdi是否是该用户bind的vdi
    public static String SN = null;
    public static String SOFTHARDID = null;
    public static String VDI_VERSION = null;

    public static boolean ISVIPUSER;


    public static boolean islandscape = false;

    public static boolean isScreenRecoder = false; //判断是否在屏幕录制中

    public static String ecu_model;//动力故障码配置位置
    public static String ECUUPLOADURL = "";

    private static String ATS_0 = "/storage/sdcard0" + "/" + APP_PATH + "/"
            + "Diagnostics/";
    private static String ATS_1 = "/storage/sdcard1" + "/" + APP_PATH + "/"
            + "Diagnostics/";

    public static boolean isRemotingFlash;//是否正在远程刷写


    public static String getDiaSysRes() {
        return BASE_CONFIG_PATH + DIAGNOSTICSYSRES;
    }

    public static String getDiaUserData() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath() + DIAGNOSTICUSERDATA;
        }
        return BASE_CONFIG_PATH + DIAGNOSTICUSERDATA;
    }

    public static String getFLASHZIPFILES() {
        return BASE_CONFIG_PATH + FLASHZIPFILES;
    }

    public static final int SOCKET_READ_TIMEOUT_MILLS = 60 * 1000;//socket读取超时时间


    public static void updateAtsStorage() {
        String root = getRootDir();
        if (root == null) {
            LogMds.d("storage", "sdcard not ready!!!!");
            return;
        }
        setAtsStorage(root);
        createAppPath();
        createNoMediaFile();
        createDownloadPath();
    }

    private static void createNoMediaFile() {
        File nomediaFile = new File(ATS_PATH + ".nomedia");

        if (!nomediaFile.exists()) {
            try {
                nomediaFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    private static void createAppPath() {
        File appFile = new File(ATS_PATH);

        if (!appFile.exists()) {
            appFile.mkdir();
        }

    }

    private static void createDownloadPath() {
        File appFile = new File(getDownLoadPath());
        LogMds.i("cdz", "download path=" + getDownLoadPath());
        if (!appFile.exists()) {
            appFile.mkdirs();
        }

        LogMds.i("cdz", "download exists=" + appFile.exists());

    }

    private static void setAtsStorage(String root) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            root = CommUtils.getContext().getExternalFilesDir(null).getParent();
            ROOT_DIR = root;
            BASE_CONFIG_PATH = root + "/" + APP_PATH + "/" + "Diagnostics/";
            ATS_PATH = root + "/" + APP_PATH + "/";

            LOGPATH = root + "/" + APP_PATH + "/log/";
            LogMds.e("cdz", "root=" + root);
            LogMds.e("cdz", "LOGPATH=" + LOGPATH);
            return;
        }
        ROOT_DIR = root;
        BASE_CONFIG_PATH = root + "/" + APP_PATH + "/" + "Diagnostics/";
        ATS_PATH = root + "/" + APP_PATH + "/";

        LOGPATH = root + "/" + APP_PATH + "/log/";
        LogMds.e("cdz", "root=" + root);
        LogMds.e("cdz", "LOGPATH=" + LOGPATH);


    }

    public static String getPublicAppPath() {
//        return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/" + APP_PATH + "/";
        return Config.ATS_PATH;
    }

    public static String getTempPath1() {
        return ATS_PATH + "temp1/";
    }

    public static String getTempPath2() {
        return ATS_PATH + "temp2/";
    }

    public static String getDownLoadPath() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath() + "Download/";
        }
        return Config.ATS_PATH + "/" + "Download/";
    }
    public static String getCache() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath() + "cache/";
        }
        return Config.ATS_PATH + "/" + "cache/";
    }
    public static String getVoice() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath() + "voice/";
        }
        return Config.ATS_PATH + "/" + "voice/";
    }

    public static String getDeviceUpdatePath() {
        return Config.ATS_PATH + "DeviceUpdate/";
    }

    /**
     * 动力优化文件目录
     *
     * @return
     */
    public static String getDongLiyhPath() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath() + "DongLiyh/";
        }
        return Config.ATS_PATH + "/" + "DongLiyh/";
    }

    /**
     * 动力优化文件目录
     *
     * @return
     */
    public static String getDongLiyhPathDownLoad() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath() + "DongLiyh/download/";
        }
        return Config.ATS_PATH + "/" + "DongLiyh/download/";
    }

    /**
     * 动力优化文件目录
     *
     * @return
     */
    public static String getDongLiyhTempPath() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath() + "DongLiyh/temp/";
        }
        return Config.ATS_PATH + "/" + "DongLiyh/temp/";
    }

    public static String getEcuFileDownloadPath() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return getPublicAppPath();
        }
        return Config.BASE_CONFIG_PATH;
    }


    public static String getRootDir() {
        Boolean atsisSdard0 = new File(ATS_0).exists();
        Boolean atsisSdard1 = new File(ATS_1).exists();
        Boolean atsisSdcard = new File(BASE_CONFIG_PATH).exists();
        Boolean atsisSdcardmnt = new File(MNTPATH).exists();

        if (atsisSdcard) {
            return android.os.Environment
                    .getExternalStorageDirectory().getAbsolutePath();
        } else if (atsisSdard0) {
            return SDCARD0;
        } else if (atsisSdard1) {
            return SDCARD1;
        } else if (atsisSdcardmnt) {
            return SDCARD2;
        }
        Boolean isSdard0 = new File(SDCARD0).exists();
        Boolean isSdard1 = new File(SDCARD1).exists();
        Boolean isSdcard = new File(ROOT_DIR).exists();
        Boolean isSdcardmnt = new File(SDCARD2).exists();
        if (isSdcard) {
            return android.os.Environment
                    .getExternalStorageDirectory().getAbsolutePath();
        } else if (isSdard0) {
            return SDCARD0;
        } else if (isSdard1) {
            return SDCARD1;
        } else if (isSdcardmnt) {
            return SDCARD2;
        }
        return null;
    }

    public static final int WIDGET_SPACE=4;//一行能放下的widget占用空间

    //        public static final String HOST="192.168.0.162:13000";//本地测试地址
//    public static final String HOST="192.168.3.56:13000";//本地测试地址

    public static final String HOST = "192.168.0.188:13000";//本地测试地址
    public static String SERVER_URL = "http://" + HOST;// 服务器地址
    public static String webSocketServerUrl = "ws://" + Config.HOST + "/websocket";



//    public static final String HOST = "www.hktf1688.cn";//线上地址
//    public static String SERVER_URL = "https://" + HOST + "/api";// 服务器地址
//
//
//    public  static String webSocketServerUrl = "wss://"+ Config.HOST +"/websocket";


    public static String CLIENTNAME = "moedokilock";


}